package de.uni_saarland.coli.doclists.index.filesystem;

/**
 * 
 * @author stefan
 * 
 *         Stores all the object, its use frequency and its id(index in
 *         DiscList)
 * 
 * @param <T>
 *            Type of cached objects (needs to implement IToBytes)
 */
public class ObjectCacheDataItem<T> {
	/**
	 * The id
	 */
	private int id;
	/**
	 * The object
	 */
	private T item;
	/**
	 * number of uses
	 */
	private int useFreq;

	/**
	 * Constructor useFreq = 1
	 * 
	 * @param id
	 *            its id
	 * @param item
	 *            the object
	 */
	public ObjectCacheDataItem(int id, T item) {
		this.item = item;
		this.id = id;
		this.useFreq = 1;
	}

	/**
	 * Increses the frequency
	 */
	public void increaseCount() {
		this.useFreq++;
	}

	/**
	 * Returns the id.
	 * 
	 * @return the id
	 */
	public int getID() {
		return this.id;
	}

	/**
	 * Sets the id
	 * 
	 * @param id
	 *            the id
	 */
	public void setID(int id) {
		this.id = id;
	}

	/**
	 * Returns the object
	 * 
	 * @return the object
	 */
	public T getItem() {
		return item;
	}

	/**
	 * Sets the object
	 * 
	 * @param item
	 *            the object
	 */
	public void setItem(T item) {
		this.item = item;
	}

	/**
	 * Returns the frequency
	 * 
	 * @return the frequency
	 */
	public int getFrequency() {
		return useFreq;
	}

	/**
	 * Sets the frequency
	 * 
	 * @param freq
	 *            the frequency
	 */
	public void setFrequency(int freq) {
		this.useFreq = freq;
	}

	@Override
	public String toString() {
		return "<" + this.item.toString() + ", " + this.id + ", "
				+ this.useFreq + ">";
	}

}
